#include "usrList.h"

UsrList *mkUsrList()
{
	UsrList *list = (UsrList*)malloc(sizeof(UsrList));
	if (NULL == list)
	{
		printf("malloc list failed\n");
		exit(EXIT_FAILURE);
	}
	memset(list, 0, sizeof(UsrList));
	return list;
}
UsrNode *mkUsrNode()
{
	UsrNode *node = (UsrNode*)malloc(sizeof(UsrNode));
	if (NULL == node)
	{
		printf("malloc node failed\n");
		exit(EXIT_FAILURE);
	}
	memset(node, 0, sizeof(UsrNode));
	return node;
}
void insert(UsrList *list, UsrNode *node)
{
	if (NULL == list || NULL == node)
	{
		return;
	}

	node->pNext = list->pFirstNode;
	list->pFirstNode = node;
	list->iLen++;
}
UsrNode *findUsrByName(const UsrList *list, const char *name)
{
	UsrNode *node = NULL;
	if (NULL != list && NULL != name)
	{
		node = list->pFirstNode;
		while (NULL != node)
		{
			if (0 == strcmp(name, node->caUsrName))
			{
				break;
			}
			node = node->pNext;	
		}
	}

	return node;	
}
void display(const UsrList *list)
{
	if (NULL != list)
	{
		UsrNode *node = list->pFirstNode;
		while (NULL != node)
		{
			printf("usrname:%s;usrpwd:%s;age:%d\n"
				   , node->caUsrName, node->caUsrPwd
				   , node->iAge);
			node = node->pNext;
		}
	}
}



